import { Router } from '@fmfe/genesis-app';
import NProgress from 'nprogress'; // Progress 进度条
import 'nprogress/nprogress.css'; // Progress 进度条样式

/**
 * 提供一个工厂函数，创建一个路由对象
 */
export const createRouter = () => {
    let router = new Router({
        mode: 'history',
        routes: [
            {
                path: '/',
                name: 'home',
                component: () =>
                    import('../views/home.vue')
            },
            {
                path: '/test',
                name: 'test',
                component: () =>
                    import('../views/test.vue')
            },
            {
                path: '/signin',
                name: 'signin',
                component: () =>
                    import('../views/signin.vue')
            }
        ],
    });

    router.beforeEach((to, form, next) => {
        if ((process as any).browser) {
            NProgress.start();
        }

        // next({
        //     name: 'test'
        // });
        next();

        if ((process as any).browser) {
            NProgress.done();
        }
    });

    return router;
};
